var app = getApp()
var Utils = require('../../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    inquiry: "",
    upload_picture_list: [],
    typedate: 0,
    times: ""
  },
  //删除图片
  deleteimg: function (e) {
    var that = this;
    var i = e.currentTarget.dataset.index;
    var imgArr = that.data.upload_picture_list;
    imgArr.splice(i, 1);
    that.setData({
      upload_picture_list: imgArr
    })
  },
  // 上传图片
  uploadimg: function () {
    let that = this;
    var uniacid = app.siteInfo.uniacid
    var data_arr = that.data.upload_picture_list;
    wx.chooseImage({
      count: 5-that.data.upload_picture_list.length,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths
        for (var i = 0; i < tempFilePaths.length; i++) {
          
          wx.uploadFile({
            url: that.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Uploadback&m=hyb_yl',
            filePath: tempFilePaths[i],
            name: 'upfile',
            formData: [],
            success: function (res) {
              console.log(res)
              data_arr.push(res.data)
              that.setData({
                upload_picture_list: data_arr,
                typedate: 1
              })
            }
          })
        }
      }
    })
  },
  //提交表单
  infomationbtn(e) {
    var that = this
    let vals = e.detail.value;
    var time_leng = that.data.time_leng
    let reg = /^1[3456789]\d{9}$/;
    var zid = that.data.zid
    var data_time = that.data.data_time
    var month_time = that.data.month_time
    var week = that.data.week
    var msg = vals.describe
    var phone = vals.tell
    let imgs = that.data.upload_picture_list;
    var zongtime = that.data.zongtime
    var values = e.detail.value
    var zid = that.data.zid
    var server = that.data.server
    var typedate = that.data.typedate
    console.log(zid, data_time, month_time, week, msg, phone, server)
    var openid = wx.getStorageSync('openid')
    var money = that.data.money
    var addnum = that.data.addnum
    var privateNum = that.data.privateNum
    var arr = {
      'text': vals.describe,
      'upload_picture_list': imgs,
      'typedate': typedate
    }
    var conets = JSON.stringify(arr);
    if (!reg.test(vals.tell)) {
      wx.showToast({
        title: '请填写接听手机',
        icon: 'none'
      })
    } else if (vals.describe == "") {
      wx.showToast({
        title: '请填写症状描述',
        icon: 'none'
      })
    } else {
      let imgs = this.data.upload_picture_list;
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/huanzhexinxi/huanzhexinxi?inquiry=' + this.data.inquiry + '&zid=' + zid + '&data_time=' + data_time + '&month_time=' + month_time + '&week=' + week + '&msg=' + msg + '&phone=' + phone + '&key_words=' + server + '&conets=' + conets + '&time_leng=' + time_leng + '&money=' + money + '&addnum=' + addnum + '&privateNum=' + privateNum + '&arr=' + conets,
      })
    }
  },
  result() {
    wx.navigateBack({

    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    var bgc = wx.getStorageSync('color')
    var time_leng = options.time_leng
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    let that = this
    var zid = options.zid
    var data_time = options.yearDate
    var month_time = options.times
    var week = options.day
    var money = options.money
    var addnum = options.addnum
    var privateNum = options.privateNum
    app.util.request({
      'url': 'entry/wxapp/hzbingli.url',
      success: function (res) {
        that.setData({
          url: res.data,
        })
      }
    })
    this.setData({
      server: options.server,
      zongtime: options.zongtime,
      zid: zid,
      data_time: data_time,
      month_time: month_time,
      week: week,
      time_leng: time_leng,
      money: money,
      addnum: addnum,
      privateNum: privateNum
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

})